﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DDD4Fun
{
    public static class classic
    {

        public static void quicksort(this int[] array,int start,int end)
        {
            int privotindex = 0;
            if (start < end)
            {
                privotindex = findprivot(array, start, end);
                quicksort(array, start, privotindex);
                quicksort(array, privotindex + 1, end);
            }
        }

        public static int findprivot(int[] array, int start, int end)
        {
            int privot = 0, i = start, j = end;
            privot = array[i];
            while (i < j)
            {
                while (i < j && array[j] >= privot)
                    j--;
                if (i < j)
                {
                    swap(array, i, j);
                    i++;
                }

                array.print();

                while (i < j && array[i] <= privot)
                    i++;
                if (i < j)
                {
                    swap(array, i, j);
                    j--;
                }

                array.print();

            }
            return i;
        }

        public static void swap(int[] array, int i, int j)
        {
            int temp = array[i];
            array[i] = array[j];
            array[j] = temp;
        }

        public static void print(this int[] array)
        {
            string dd = "";
            foreach (int i in array)
            {
                dd += i.ToString() + ",";
              

            }

            Console.WriteLine(dd);
        }

    }
}
